home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / pbaction.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  5KB  |  240 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13. unsigned char *pbaction_videoram2,*pbaction_colorram2;
  14. WRITE_HANDLER( pbaction_videoram2_w );
  15. WRITE_HANDLER( pbaction_colorram2_w );
  16. static unsigned char *dirtybuffer2;
  17. static struct osd_bitmap *tmpbitmap2;
  18. static int scroll;
  19. static int flipscreen;
  20.  
  21.  
  22.  
  23. /***************************************************************************
  24.  
  25.   Start the video hardware emulation.
  26.  
  27. ***************************************************************************/
  28. int pbaction_vh_start(void)
  29. {
  30.     int i;
  31.  
  32.  
  33.     if (generic_vh_start() != 0)
  34.         return 1;
  35.  
  36.     if ((dirtybuffer2 = malloc(videoram_size)) == 0)
  37.     {
  38.         generic_vh_stop();
  39.         return 1;
  40.     }
  41.     memset(dirtybuffer2,1,videoram_size);
  42.  
  43.     if ((tmpbitmap2 = osd_create_bitmap(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
  44.     {
  45.         free(dirtybuffer2);
  46.         generic_vh_stop();
  47.         return 1;
  48.     }
  49.  
  50.     /* leave everything at the default, but map all foreground 0 pens as transparent */
  51.     for (i = 0;i < 16;i++) palette_used_colors[8 * i] = PALETTE_COLOR_TRANSPARENT;
  52.  
  53.     return 0;
  54. }
  55.  
  56.  
  57. /***************************************************************************
  58.  
  59.   Stop the video hardware emulation.
  60.  
  61. ***************************************************************************/
  62. void pbaction_vh_stop(void)
  63. {
  64.     osd_free_bitmap(tmpbitmap2);
  65.     free(dirtybuffer2);
  66.     generic_vh_stop();
  67. }
  68.  
  69.  
  70.  
  71. WRITE_HANDLER( pbaction_videoram2_w )
  72. {
  73.     if (pbaction_videoram2[offset] != data)
  74.     {
  75.         dirtybuffer2[offset] = 1;
  76.  
  77.         pbaction_videoram2[offset] = data;
  78.     }
  79. }
  80.  
  81.  
  82.  
  83. WRITE_HANDLER( pbaction_colorram2_w )
  84. {
  85.     if (pbaction_colorram2[offset] != data)
  86.     {
  87.         dirtybuffer2[offset] = 1;
  88.  
  89.         pbaction_colorram2[offset] = data;
  90.     }
  91. }
  92.  
  93.  
  94.  
  95. WRITE_HANDLER( pbaction_scroll_w )
  96. {
  97.     scroll = -(data-3);
  98. }
  99.  
  100.  
  101.  
  102. WRITE_HANDLER( pbaction_flipscreen_w )
  103. {
  104.     if (flipscreen != (data & 1))
  105.     {
  106.         flipscreen = data & 1;
  107.         memset(dirtybuffer,1,videoram_size);
  108.         memset(dirtybuffer2,1,videoram_size);
  109.     }
  110. }
  111.  
  112.  
  113.  
  114. /***************************************************************************
  115.  
  116.   Draw the game screen in the given osd_bitmap.
  117.   Do NOT call osd_update_display() from this function, it will be called by
  118.   the main emulation engine.
  119.  
  120. ***************************************************************************/
  121. void pbaction_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  122. {
  123.     int offs;
  124.  
  125.  
  126.     /* recalc the palette if necessary */
  127.     if (palette_recalc())
  128.     {
  129.         memset(dirtybuffer,1,videoram_size);
  130.         memset(dirtybuffer2,1,videoram_size);
  131.     }
  132.  
  133.  
  134.     /* for every character in the Video RAM, check if it has been modified */
  135.     /* since last time and update it accordingly. */
  136.     for (offs = videoram_size - 1;offs >= 0;offs--)
  137.     {
  138.         if (dirtybuffer[offs])
  139.         {
  140.             int sx,sy,flipx,flipy;
  141.  
  142.  
  143.             dirtybuffer[offs] = 0;
  144.  
  145.             sx = offs % 32;
  146.             sy = offs / 32;
  147.             flipx = colorram[offs] & 0x40;
  148.             flipy = colorram[offs] & 0x80;
  149.             if (flipscreen)
  150.             {
  151.                 sx = 31 - sx;
  152.                 sy = 31 - sy;
  153.                 flipx = !flipx;
  154.                 flipy = !flipy;
  155.             }
  156.  
  157.             drawgfx(tmpbitmap,Machine->gfx[0],
  158.                     videoram[offs] + 0x10 * (colorram[offs] & 0x30),
  159.                     colorram[offs] & 0x0f,
  160.                     flipx,flipy,
  161.                     8*sx,8*sy,
  162.                     &Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  163.         }
  164.  
  165.         if (dirtybuffer2[offs])
  166.         {
  167.             int sx,sy,flipy;
  168.  
  169.  
  170.             dirtybuffer2[offs] = 0;
  171.  
  172.             sx = offs % 32;
  173.             sy = offs / 32;
  174.             flipy = pbaction_colorram2[offs] & 0x80;
  175.             if (flipscreen)
  176.             {
  177.                 sx = 31 - sx;
  178.                 sy = 31 - sy;
  179.                 flipy = !flipy;
  180.             }
  181.  
  182.             drawgfx(tmpbitmap2,Machine->gfx[1],
  183.                     pbaction_videoram2[offs] + 0x10 * (pbaction_colorram2[offs] & 0x70),
  184.                     pbaction_colorram2[offs] & 0x0f,
  185.                     flipscreen,flipy,
  186.                     8*sx,8*sy,
  187.                     &Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  188.         }
  189.     }
  190.  
  191.  
  192.     /* copy the background */
  193.     copyscrollbitmap(bitmap,tmpbitmap2,1,&scroll,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  194.  
  195.  
  196.     /* Draw the sprites. */
  197.     for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
  198.     {
  199.         int sx,sy,flipx,flipy;
  200.  
  201.  
  202.         /* if next sprite is double size, skip this one */
  203.         if (offs > 0 && spriteram[offs - 4] & 0x80) continue;
  204.  
  205.         sx = spriteram[offs+3];
  206.         if (spriteram[offs] & 0x80)
  207.             sy = 225-spriteram[offs+2];
  208.         else
  209.             sy = 241-spriteram[offs+2];
  210.         flipx = spriteram[offs+1] & 0x40;
  211.         flipy =    spriteram[offs+1] & 0x80;
  212.         if (flipscreen)
  213.         {
  214.             if (spriteram[offs] & 0x80)
  215.             {
  216.                 sx = 224 - sx;
  217.                 sy = 225 - sy;
  218.             }
  219.             else
  220.             {
  221.                 sx = 240 - sx;
  222.                 sy = 241 - sy;
  223.             }
  224.             flipx = !flipx;
  225.             flipy = !flipy;
  226.         }
  227.  
  228.         drawgfx(bitmap,Machine->gfx[(spriteram[offs] & 0x80) ? 3 : 2],    /* normal or double size */
  229.                 spriteram[offs],
  230.                 spriteram[offs + 1] & 0x0f,
  231.                 flipx,flipy,
  232.                 sx+scroll,sy,
  233.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  234.     }
  235.  
  236.  
  237.     /* copy the foreground */
  238.     copyscrollbitmap(bitmap,tmpbitmap,1,&scroll,0,0,&Machine->drv->visible_area,TRANSPARENCY_PEN,palette_transparent_pen);
  239. }
  240.